package com.ruoyi.stream.framework.core.workDomain.io.ioBehavior;

import com.ruoyi.stream.framework.core.workDomain.SingleIOTask;
import com.ruoyi.stream.framework.core.workDomain.SingleIOTaskGroup;
import com.ruoyi.stream.framework.core.workDomain.io.IOBehavior;

import java.io.IOException;

public class ProductIOResource implements IOBehavior {
    @Override
    public void act(SingleIOTask task) {
        try {
            int read = task.getInputStream().read(task.getCache());
            if (read < 0 ){
                task.finish();
            }else {
                task.setReadLength(task.getReadLength() + read);
            }
            ((SingleIOTaskGroup)task.getGroup()).getWaitForConsume().add(task);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
